package com.mouse.controller.user;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mouse.common.lang.Result;
import com.mouse.entity.*;
import com.mouse.entity.vo.DoubleAlleleVO;
import com.mouse.entity.vo.GeneCategoryVO;
import com.mouse.mapper.*;
import com.mouse.service.GeneCategoryService;
import io.jsonwebtoken.lang.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author godson
 * @since 2022-08-05
 */
@RestController
@RequestMapping("/gene-category")
public class GeneCategoryController {


    @Autowired
    GeneCategoryMapper geneCategoryMapper;

    @Autowired
    private DiseaseMapper diseaseMapper;

    @Autowired
    private DoubleAllelesMapper doubleAllelesMapper;

    @Autowired
    private GeneAlleleMapper geneAlleleMapper;

    @Autowired
    private GeneCompositionMapper geneCompositionMapper;

    @Autowired
    private PhenotypeMapper phenotypeMapper;

    @Autowired
    private ReferenceMapper referenceMapper;

    @Autowired
    GeneCategoryService geneCategoryService;

    /***
     * 根据键值对查询满足条件的记录，并分页
     * @param key
     * @param value
     * @param pageNum 第几页
     * @param pageSize 一页有几个记录
     * @return
     */
    @GetMapping("/get/")
    public Result select(@Validated @RequestParam String key, @RequestParam String value, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize ){
        IPage<GeneCategory> page = new Page<>(pageNum,pageSize);
        IPage<GeneCategory> info = geneCategoryService.getInfoByMap(page, key, value);
        if(info.getSize()==0){
            return Result.fail("无对应记录");
        }
        return Result.succ(info);
    }

    @GetMapping("/info/{gid}")
    public Result getInfo(@PathVariable(name="gid") Long gid){
        GeneCategory geneCategory = geneCategoryService.getById(gid);
        GeneCategoryVO geneCategoryVO = geneCategoryService.getGeneCategoryVO(geneCategory);
        return Result.succ(geneCategoryVO);

    }
//    @GetMapping("/gene-composition/{gid}/{currentPage}/{pageSize}")
//    public Result getGeneCompositionByGid(@PathVariable(name="gid") Long gid,
//                                    @PathVariable Integer currentPage,
//                                    @PathVariable Integer pageSize){
//        Page<GeneComposition> page = new Page<>(currentPage,pageSize);
//        Page<GeneComposition> pages = geneCompositionMapper.getGeneCompositionByGid(page, gid);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/double-alleles/{gid}/{currentPage}/{pageSize}")
//    public Result getDoubleAllelesByGid(@PathVariable(name="gid") Long gid,
//                                     @PathVariable Integer currentPage,
//                                     @PathVariable Integer pageSize){
//        Page<DoubleAlleles> page = new Page<>(currentPage,pageSize);
//        Page<DoubleAlleles> pages = doubleAllelesMapper.getDoubleAllelesByGid(page, gid);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/reference/{gid}/{currentPage}/{pageSize}")
//    public Result getReferenceByGid(@PathVariable(name="gid") Long gid,
//                                        @PathVariable Integer currentPage,
//                                        @PathVariable Integer pageSize){
//        Page<Reference> page = new Page<>(currentPage,pageSize);
//        Page<Reference> pages = referenceMapper.getReferenceByGid(page, gid);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/phenotype/{gid}/{currentPage}/{pageSize}")
//    public Result getPhenotypeByGid(@PathVariable(name="gid") Long gid,
//                                    @PathVariable Integer currentPage,
//                                    @PathVariable Integer pageSize){
//        Page<Phenotype> page = new Page<>(currentPage,pageSize);
//        Page<Phenotype> pages = phenotypeMapper.getPhenotypeByGid(page, gid);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/gene-allele/{gid}/{currentPage}/{pageSize}")
//    public Result getGeneAlleleByGid(@PathVariable(name="gid") Long gid,
//                                    @PathVariable Integer currentPage,
//                                    @PathVariable Integer pageSize){
//        Page<GeneAllele> page = new Page<>(currentPage,pageSize);
//        Page<GeneAllele> pages = geneAlleleMapper.getGeneAllelesByGid(page, gid);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/disease/{gid}/{currentPage}/{pageSize}")
//    public Result getDiseaseByGid(@PathVariable(name="gid") Long gid,
//                                    @PathVariable Integer currentPage,
//                                    @PathVariable Integer pageSize){
//        Page<Disease> page = new Page<>(currentPage,pageSize);
//        Page<Disease> pages = diseaseMapper.getDiseaseByGid(page, gid);
//        return Result.succ(pages);
//    }





//    @GetMapping("/by-gene-id/{geneID}")
//    public Result getGeneCategoryByGeneID(@PathVariable(name="geneID") Long geneID){
//        Page<GeneCategory> page = new Page<>(1,10);
//        Page<GeneCategory> pages = geneCategoryMapper.getGeneCategoryByGeneID(page, geneID);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/by-name/{name}")
//    public Result getGeneCategoryByName(@PathVariable(name="name") String name){
//        Page<GeneCategory> page = new Page<>(1,10);
//        Page<GeneCategory> pages = geneCategoryMapper.getGeneCategoryByGeneName(page, name);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/by-alias/{alias}")
//    public Result getGeneCategoryByAlias(@PathVariable(name="alias") String alias){
//        Page<GeneCategory> page = new Page<>(1,10);
//        Page<GeneCategory> pages = geneCategoryMapper.getGeneCategoryByGeneAlias(page, alias);
//        return Result.succ(pages);
//    }
//
//    @GetMapping("/by-homology/{homology}")
//    public Result getGeneCategoryByHomology(@PathVariable(name="homology") String homology){
//        Page<GeneCategory> page = new Page<>(1,10);
//        Page<GeneCategory> pages = geneCategoryMapper.getGeneCategoryByGeneHomology(page, homology);
//        return Result.succ(pages);
//    }



}
